package org.codert.wxpay.test;

import ch.qos.logback.core.net.ObjectWriter;

import java.io.*;
import java.net.*;
import java.nio.charset.StandardCharsets;
import java.sql.DriverManager;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.ConcurrentModificationException;
import java.util.List;

/**
 * 31070CFD027C3F14C75575D0022159F0B864E7AD
 * @author: TanJingyu
 * @create: 2021-08-27 22:21
 **/
public class FileMain<K> implements Serializable{
    private K k;
    private static final String LOCATION = "D:\\\\影音图片\\\\test.txt";

    public static void main(String[] args) throws Exception {
//        windows();

//        objectStream();

//        SeriList();

//        test();

//        afterTest();

//        System.out.println(0xFFFF);

//        list();

//        System.out.println(0B1);
//        System.out.println(0B11);
//        System.out.println(0B111);
//        System.out.println(0B1111);
//        System.out.println(0B11111);
//        System.out.println(0B11111 & 0B1111);
//        System.out.println(0B11111 % 0B1111);
//        System.out.println(0b1);
//        System.out.println(0b10);
//        System.out.println(0b100);
//        System.out.println(0b1000);
//        System.out.println(0b10000);
//
//        System.out.println(17 % 0b10000);
//        System.out.println(17 & 0b1111);
//        int h = 0B10101011110011010000000000000000;
//        System.out.println(h);
//        System.out.println(h ^ (h >>> 16));

//        System.out.println(0b1000);
//        System.out.println(0b10011);
//        System.out.println(0b1000 & 0b10011);

//        ServerSocket server = new ServerSocket();
//        InetSocketAddress inetSocketAddress = new InetSocketAddress(InetAddress.getByName("localhost"), 80);
//        server.bind(inetSocketAddress);
//        while (true) {
//            Socket socket = server.accept();
//            InputStream inputStream = socket.getInputStream();
//            System.out.println("收到请求了。。。");
//            int count = 0;
//            int by = 0;
//            while ((by = inputStream.read()) != -1) {
//                System.out.println(by);
//                count++;
//            }
//            System.out.println(count);
//            OutputStream outputStream = socket.getOutputStream();
//            outputStream.write("abcd".getBytes(StandardCharsets.UTF_8));
//            outputStream.close();
//        socket.close();
//        }

//        // 看成两个操作，先声明了一个haha字符串，则在常量池中找，没找到则创建。
//        // 然后new String，堆中的String实例持有常量池中的haha。
//        // b指向的也是常量池中的。
//        // 结论：直接a.equalse(b)不相等，因为一个堆一个池
//        // a.intern().equalse(b.intern())相等，因为指向都是池。
//        String a = new String("haha");
//        String b = "haha";
//
//        // 此时字符串常量池中创建并存储de和mo，但是不存在demo，
//        // 堆中存在new的demo，c指向它
//        String c = new String("de") + new String("mo");
//        // d在常量池中创建demo，并指向它
//        String d = "demo";
//        // 不相等，一个是堆，一个是常量池
//        System.out.println(c.equals(d));
//        // intern方法，相等。
//        // c.intern会先去常量池查找是否存在demo，存在则返回，不存在则去堆中查找然后字符串池指向堆中的那个
//        // 此时c.intern()返回的是常量池中的，因为上边string d = "demo";创建了
//        // 分析d同理
//        System.out.println(c.intern().equals(d.intern()));


        DriverManager.getConnection("");
        System.out.println(Class.forName("org.codert.wxpay.test.FileMain"));
    }

    private static void list() {
        ArrayList<Integer> objects = new ArrayList<>();
        objects.add(1);
        objects.add(2);
        objects.add(3);

        List<Integer> integers = Arrays.asList(2, 3);

        objects.removeAll(integers);
    }

    private static void test() throws IOException {
        OutputStreamWriter outputStreamWriter = new OutputStreamWriter(new FileOutputStream(LOCATION));
        outputStreamWriter.write("你");
        outputStreamWriter.write("好");
        outputStreamWriter.close();

        InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(LOCATION));
        char[] buff = new char[3];
        System.out.println(inputStreamReader.read(buff));
        System.out.println(buff);
    }

    private static void afterTest() throws Exception {
        Demo demo = new Demo("|忘记");
        seObj(demo);
        reObj();
    }

    public static void seObj(Object o) throws Exception {
        ObjectOutputStream objectOutputStream = new ObjectOutputStream(new FileOutputStream("D:\\\\影音图片\\\\test.txt"));
        objectOutputStream.writeObject(o);
    }

    public static void reObj() throws Exception {
        ObjectInputStream objectInputStream = new ObjectInputStream(new FileInputStream("D:\\\\影音图片\\\\test.txt"));
        System.out.println(objectInputStream.readObject());
    }

    private static void SeriList() throws IOException, ClassNotFoundException {
        ArrayList<String> strings = new ArrayList<>();
        strings.add("你好啊");

        ObjectOutputStream objectOutputStream = new ObjectOutputStream(new FileOutputStream("D:\\\\影音图片\\\\test.txt"));
        objectOutputStream.writeObject(strings);

        ObjectInputStream objectInputStream = new ObjectInputStream(new FileInputStream("D:\\\\影音图片\\\\test.txt"));
        System.out.println(objectInputStream.readObject());
    }

    private static void objectStream() throws IOException {
        ObjectOutputStream objectOutputStream = new ObjectOutputStream(new FileOutputStream("D:\\\\影音图片\\\\test.txt"));
        objectOutputStream.writeObject(new FileMain<>());
    }

    private static void windows() throws IOException, InterruptedException {
        String file = "D:\\\\影音图片\\\\yellow\\\\02\\\\桃乃木かな\\\\IPX202.mp4";
        Runtime runtime = Runtime.getRuntime();

        Process exec = runtime.exec("cmd /k echo 1 >> D:\\\\影音图片\\\\yellow\\\\02\\\\桃乃木かな\\\\IPX202.mp4");
        InputStream inputStream = exec.getInputStream();

        int i = 0;
        while ((i = inputStream.read()) != -1) {
            System.out.println(i);
        }
        exec.waitFor();
    }

    public K getk() {
        return this.k;
    }

    public static <T> T get() {
        FileMain<?> stringFileMain = new FileMain<String>();
        return null;
    }

    public static class Demo<T> implements Serializable{
        private static final long serialVersionUID = 8683452581122892189L;
        private Object o;

        public void add(T t) {
            this.o = t;
        }

        public T get() {
            return (T)this.o;
        }

        private transient String name;

        public Demo(String name) {
            this.name = name;
        }

        @Override
        public String toString() {
            return name;
        }

        private void writeObject(java.io.ObjectOutputStream s)
                throws java.io.IOException{
//            s.defaultWriteObject(); nbh

            // Write out size as capacity for behavioural compatibility with clone()
//            s.writeObject(name);
            s.writeObject("你好");
        }
    }
}
